import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class TaFramMedlem extends HttpServlet{
    PrintWriter out;
    
//----------------doPost---------------------------------**
    public void doPost(HttpServletRequest req, HttpServletResponse res){
        
        try{
            out=res.getWriter();
        }catch(Exception e){}
        
        listaMedlemmar();
    }
    
//----------------doGet------------------------------------**
    public void doGet(HttpServletRequest req, HttpServletResponse res){
        
        try{
            out=res.getWriter();
        }catch(Exception e){}
        
        listaMedlemmar();
    }
    
//--------------listar upp alla medlemmar-------------------------**
    public void listaMedlemmar(){
        
        ResultSet rs = null;
        
        
        try{
            DBkoppling.setKoppling();
            rs=DBkoppling.getTabell("*", "Medlem", "alias");
            DBkoppling.kopplaNer();
        }catch(SQLException e){
            out.println("Could not find table. SQL errors follows: <BR>");
            out.println("SQLException: " + e.getMessage() + "<BR>");
            out.println("SQLState:     " + e.getSQLState() + "<BR>");
            out.println("VendorError:  " + e.getErrorCode());
            out.println("</BODY></HTML>");
        }//catch
        
        try{
            ResultSetMetaData rmd = rs.getMetaData();
            int columns = rmd.getColumnCount();
            out.print("<table border=1 cellspacing=2 cellpadding=1> <tr>");
            out.print("<TR>");
            
            for(int i=1; i <= columns; i++){
                out.print("<th width=100 align=center>" + rmd.getColumnName(i) + "</th>");
            }//for
            
            while(rs.next()){
                out.print("<table border=1 cellspacing=2 cellpadding=1> <tr>");
                
                out.print("<tr>");
                for(int i=1; i <= columns; i++){
                    if(i!=3){
                        
                        out.print("<td width=100 align=center>" + rs.getString(i) + "</td>");
                    }else{
                        out.print("<td width=100 align=center><A HREF=./VisaMedlemsInfo?alias="+rs.getString(i)+">"+rs.getString(i)+"</A></td>");
                    }//else
                }//for
                
                out.print("	</TD>");
                out.print("</TR>");
                out.print("</TABLE>");
            }//while
            
            rs=null;
            
            out.println("</tr></table>");
            out.println("</BODY></HTML>");
        }catch(Exception e){
            out.print(e);
        }//catch
    }//listaMedlemmar
}//end class
